// pages/orderDetail/refund.js
const app = getApp()
var wh = require("../../utils/wh.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order_id:'',
    ShopDetail:''
  },
  // 订单详情
  item_detail(order_id) {
    let that = this;
    wh.Post('/api/mall.order/item_detail', {
      order_id: order_id
    }, function (res) {
      console.log(res)
      that.getShopDetail(res.shop_id)
      that.setData({ 
        detail: res
      })
    })
  },
  // 删除订单
  del_order(e) {
    let that = this;
    wx.showModal({
      title: '',
      content: '是否删除该订单',
      success: function (res) {
        if (res.confirm) {
          wh.Post('/api/mall.order/del', {
            order_id: that.data.order_id
          }, function (res) {
            wx.showToast({
              title: '删除成功',
              icon: 'none',
              duration: 2000,
              complete: function () {
                setTimeout(function () {
                  wx.navigateTo({
                    url: '../order/order?c=-1'
                  })
                }, 2000);
              }
            });
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  // 取消申请退款
  cancel_refund() {
    let that = this;
    wx.showModal({
      title: '',
      content: '是否取消申请退款',
      success: function (res) {
        if (res.confirm) {
          wh.Post('/api/mall.order/cancel_refund', {
            order_id: that.data.order_id
          }, function (res) {
            wx.showToast({
              title: '取消成功',
              icon: 'none',
              duration: 2000,
              complete: function () {
                setTimeout(function () {
                  wx.navigateTo({
                    url: '../order/order?c=-1'
                  })
                }, 2000);
              }
            });
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  // 获取商家店铺详情
  getShopDetail(shop_id) {
    var that = this;
    wh.Post('/api/mall.shop/detail', {
      shop_id: shop_id
    }, function (res) {
      console.log('店铺详情', res)
      that.setData({
        ShopDetail: res,
      })
    });
  },
  call: function () {
    let that = this;
    let tell = that.data.ShopDetail.tell;
    if (tell == '' || tell == undefined) {
      wx.showModal({
        title: '提示',
        content: '联系电话未设置，不能联系',
        showCancel: false
      })
      return;
    }
    wx.makePhoneCall({
      phoneNumber: tell,
    })
  },
  // 跳转至商品详情
  toGoods(e) {
    let that = this,
      id = e.currentTarget.dataset.id,
      act_type = e.currentTarget.dataset.act_type;
    if (act_type == 1) {
      wx.navigateTo({
        url: '../details/details?goods_id=' + id,
      })
    } else if (act_type == 2) {
      wx.navigateTo({
        url: '../cutDetails/cutDetails?bargainId=' + id,
      })
    } else if (act_type == 3) {
      wx.navigateTo({
        url: '../killDetails/killDetails?seckill_id=' + id,
      })
    } else if (act_type == 4) {
      wx.navigateTo({
        url: '../groupDetails/groupDetails?group_id=' + id,
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.order_id)
    this.item_detail(options.order_id)
    this.setData({
      order_id: options.order_id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})